//
//  KLSettingTableViewController.m
//  KISSLOCK
//
//  Created by 陈宾鹏 on 16/5/6.
//  Copyright © 2016年 陈宾鹏. All rights reserved.
//

#import "KLSettingTableViewController.h"
#import "KLHelp.h"
#import "HemaConst.h"
#import "KLInstructionsViewController.h"
#import "UMFeedback.h"
#import "KLAboutViewController.h"

@interface KLSettingTableViewController ()<UIAccelerometerDelegate>
@property (nonatomic,strong) UIViewController *umFeedBackVC;
@end

@implementation KLSettingTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = NO;
    self.title = @"设置";
    //初始化导航栏
    [self naveSet];
    self.view.backgroundColor = RGB_UI_COLOR(242, 242, 242);
    self.tableView.tableFooterView = [[UIView alloc]init];
    self.umFeedBackVC = [UMFeedback feedbackModalViewController];
    
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    if(indexPath.section == 0){
        cell.textLabel.text = @"使用说明";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }else if (indexPath.section == 1){
        cell.textLabel.text = @"关于";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }else if (indexPath.section == 2){
        cell.textLabel.text = @"意见反馈";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }else if (indexPath.section == 3){
        cell.textLabel.text = @"相关政策";
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }else if (indexPath.section == 4){
        UILabel *loginOut = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
        loginOut.text = @"退出登录";
        loginOut.textAlignment = NSTextAlignmentCenter;
        loginOut.font = [UIFont systemFontOfSize:19];
        loginOut.textColor = [UIColor redColor];
        [cell.contentView addSubview:loginOut];
    }
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 16;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 5;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, UI_View_Width, 17)];
    header.backgroundColor = RGB_UI_COLOR(242, 242, 242);
    return header;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, UI_View_Width, 7)];
    footer.backgroundColor = RGB_UI_COLOR(242, 242, 242);
    return footer;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 0){
        KLInstructionsViewController *instructionVC = [[KLInstructionsViewController alloc]init];
        instructionVC.whichWeb = 2;
        [self.navigationController pushViewController:instructionVC animated:YES];
    }else if (indexPath.section == 1){
        KLAboutViewController *aboutVC = [[KLAboutViewController alloc]init];
        [self.navigationController pushViewController:aboutVC animated:YES];
    }else if (indexPath.section == 2){
        [self presentViewController:self.umFeedBackVC animated:YES completion:nil];
    }else if (indexPath.section == 3){
        KLInstructionsViewController *instructionVC = [[KLInstructionsViewController alloc]init];
        instructionVC.whichWeb = 3;
        [self.navigationController pushViewController:instructionVC animated:YES];
    }else if (indexPath.section == 4){
        [[NSNotificationCenter defaultCenter] postNotificationName:@"loginOut" object:nil userInfo:nil];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

//初始化导航栏
-(void)naveSet{
    [KLHelp navSet:self doBackHandeler:^(UIButton *backButton) {
        [backButton addTarget:self action:@selector(doBack:) forControlEvents:UIControlEventTouchUpInside];
    }];
}-(void)doBack:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
